﻿using LH.Model.PU;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using fuzhu;
using LH.Model.ST;
using System.Security.AccessControl;
using XXX.Models.AS;
using System.Xml.Linq;
using XXX.Common;
using XXX.Bo;
using LH.Model.SA;
using ZDEntity;

namespace LH.U8API.Bus
{
    public static class GetInfo
    {
        /// <summary>
        /// 构建写U8的存货档案类
        /// </summary>
        /// <param name="rdrecordimport">传入的档案</param>
        /// <param name="cConstr">连接字符串</param>
        /// <param name="bmodify">是否修改</param>
        /// <param name="rdrecord">传出</param>
        /// <returns></returns>
        public static string GetInventoryInfo(API_Inventory rdrecordimport, string cConstr, String bmodify, out API_Inventory rdrecord)
        {
            //设置存货的默认属性
            API_Inventory inv = new API_Inventory();
            if (bmodify == "1")
            {
                string sql = string.Format("select convert(char, convert(money, pubufts), 2) as ts  from inventory where cinvcode='{0}' ", rdrecordimport.cInvCode);
                string cufts = DbHelper.GetDbString(DbHelper2.ExecuteScalar(sql, cConstr));
                inv.pubufts = cufts;



                inv.dEDate = rdrecordimport.dEDate;
                inv.cModifyPerson = rdrecordimport.cModifyPerson;




            }
            else
            {
                inv.dSDate = rdrecordimport.dSDate;
                inv.cCreatePerson = rdrecordimport.cCreatePerson;
            }


            inv.cInvCode = rdrecordimport.cInvCode;

            /// <summary>
            /// 
            /// </summary>
            inv.cInvName = rdrecordimport.cInvName;
            inv.cInvAddCode = rdrecordimport.cInvAddCode;
            inv.cInvStd = rdrecordimport.cInvStd;
            /// <summary>
            /// 
            /// </summary>
            inv.cInvCCode = rdrecordimport.cInvCCode;

            /// <summary>
            /// 是否销售
            /// </summary>
            inv.bSale = rdrecordimport.bSale;

            /// <summary>
            /// 是否采购
            /// </summary>
            inv.bPurchase = rdrecordimport.bPurchase;

            /// <summary>
            /// 是否自制
            /// </summary>
            inv.bSelf = rdrecordimport.bSelf;

            /// <summary>
            /// 是否耗用
            /// </summary>
            inv.bComsume = rdrecordimport.bComsume;


            /// <summary>
            /// 
            /// </summary>
            inv.iTaxRate = rdrecordimport.iTaxRate;


            /// <summary>
            /// 
            /// </summary>
            inv.bInvQuality = rdrecordimport.bInvQuality;

            /// <summary>
            /// 
            /// </summary>
            inv.bInvBatch = rdrecordimport.bInvBatch;
            inv.bService = rdrecordimport.bService;
            inv.bInvAsset = rdrecordimport.bInvAsset;
            /// <summary>
            /// 
            /// </summary>


            inv.cDefWareHouse = rdrecordimport.cDefWareHouse;
            inv.cValueType = rdrecordimport.cValueType;
            /// <summary>
            /// 
            /// </summary>
            inv.bFree1 = rdrecordimport.bFree1;

            /// <summary>
            /// 
            /// </summary>
            inv.bConfigFree1 = rdrecordimport.bConfigFree1;

            inv.bControlFreeRange1 = rdrecordimport.bControlFreeRange1;
            /// <summary>
            /// 
            /// </summary>



            /// <summary>
            /// 计量单位组
            /// </summary>
            inv.iGroupType = rdrecordimport.iGroupType;

            /// <summary>
            /// 计量单位
            /// </summary>
            inv.cGroupCode = rdrecordimport.cGroupCode;

            /// <summary>
            /// 
            /// </summary>
            inv.cComUnitCode = rdrecordimport.cComUnitCode;


            /// <summary>
            /// 是否委外
            /// </summary>
            inv.bProxyForeign = rdrecordimport.bProxyForeign;

            inv.cInvABC = rdrecordimport.cInvABC;
            /// <summary>
            /// 
            /// </summary>
            inv.bBomMain = rdrecordimport.bBomMain;

            /// <summary>
            /// 
            /// </summary>
            inv.bBomSub = rdrecordimport.bBomSub;

            /// <summary>
            /// 
            /// </summary>
            inv.bProductBill = rdrecordimport.bProductBill;

            rdrecord = inv;
            return "ok";
        }

        /// <summary>
        /// 构建写U8的供应商档案类
        /// </summary>
        /// <param name="rdrecordimport">传入的档案</param>
        /// <param name="cConstr">连接字符串</param>
        /// <param name="bmodify">是否修改</param>
        /// <param name="rdrecord">传出</param>
        /// <returns></returns>
        public static string GetVendorInfo(AS_Vendor rdrecordimport, string cConstr, String bmodify, out AS_Vendor rdrecord)
        {
            //设置存货的默认属性
            AS_Vendor inv = new AS_Vendor();
            if (bmodify == "1")
            {
                string sql = string.Format("select convert(char, convert(money, pubufts), 2) as ts  from Vendor where cvencode='{0}' ", rdrecordimport.cVenCode);
                string cufts = DbHelper.GetDbString(DbHelper2.ExecuteScalar(sql, cConstr));
                inv.pubufts = cufts;



                inv.dEndDate = rdrecordimport.dEndDate;
                inv.cModifyPerson = rdrecordimport.cModifyPerson;




            }

            inv.dVenDevDate = rdrecordimport.dVenDevDate;
            inv.cCreatePerson = rdrecordimport.cCreatePerson;

            inv.cVenCode = rdrecordimport.cVenCode;
            inv.cVenName = rdrecordimport.cVenName;
            inv.cVenAbbName = rdrecordimport.cVenAbbName;
            inv.cVCCode = rdrecordimport.cVCCode;
            /// <summary>
            /// 
            /// </summary>
            inv.cVenAddress = rdrecordimport.cVenAddress;
            inv.dVenDevDate = rdrecordimport.dVenDevDate;
            inv.cVenPerson = rdrecordimport.cVenPerson;
            /// <summary>
            /// 
            /// </summary>
            inv.cVenHand = rdrecordimport.cVenHand;


            inv.cVenHeadCode = rdrecordimport.cVenCode;


            inv.cVenPUOMProtocol = rdrecordimport.cVenPUOMProtocol;


            inv.bVenCargo = rdrecordimport.bVenCargo;


            inv.bProxyForeign = rdrecordimport.bProxyForeign;


            inv.bVenService = rdrecordimport.bVenService;


            inv.cVenExch_name = rdrecordimport.cVenExch_name;


            rdrecord = inv;
            return "ok";
        }

        /// <summary>
        /// 构建写U8的客户档案类
        /// </summary>
        /// <param name="rdrecordimport">传入的档案</param>
        /// <param name="cConstr">连接字符串</param>
        /// <param name="bmodify">是否修改</param>
        /// <param name="rdrecord">传出</param>
        /// <returns></returns>
        public static string GetCustomerInfo(AS_Customer rdrecordimport, string cConstr, String bmodify, out AS_Customer rdrecord)
        {
            //设置存货的默认属性
            AS_Customer inv = new AS_Customer();
            if (bmodify == "1")
            {
                string sql = string.Format("select convert(char, convert(money, pubufts), 2) as ts  from Customer where ccuscode='{0}' ", rdrecordimport.cCusCode);
                string cufts = DbHelper.GetDbString(DbHelper2.ExecuteScalar(sql, cConstr));
                inv.pubufts = cufts;



                inv.dEndDate = rdrecordimport.dEndDate;
                inv.cModifyPerson = rdrecordimport.cModifyPerson;




            }
            else
            {
                inv.dCusDevDate = rdrecordimport.dCusDevDate;
                inv.cCreatePerson = rdrecordimport.cCreatePerson;
            }
            inv.cCusCode = rdrecordimport.cCusCode;
            inv.cCusHeadCode = rdrecordimport.cCusCode;
            inv.cInvoiceCompany = rdrecordimport.cCusCode;
            inv.cCusCreditCompany = rdrecordimport.cCusCode;
            /// <summary>
            /// 
            /// </summary>
            inv.cCusName = rdrecordimport.cCusName;
            inv.cCCCode = rdrecordimport.cCCCode;
            inv.cCusAbbName = rdrecordimport.cCusAbbName;
            /// <summary>
            /// 
            /// </summary>
            inv.cCusRegCode = rdrecordimport.cCusRegCode;


            inv.cCusBank = rdrecordimport.cCusBank;


            inv.cCusAccount = rdrecordimport.cCusAccount;


            inv.cCusPerson = rdrecordimport.cCusPerson;


            inv.cCusHand = rdrecordimport.cCusHand;


            inv.cCusBankCode = rdrecordimport.cCusBankCode;


            inv.cCusExch_name = rdrecordimport.cCusExch_name;


            rdrecord = inv;
            return "ok";
        }
 
        public static string GetPUBillInfo(PurBillVouch pu_BillVouch, string cConstr)
        {
            if (pu_BillVouch == null)
            {
                return "Error: 没有数据";
            }
            if (pu_BillVouch.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < pu_BillVouch.bodies.Count; i++)
            {
                if (pu_BillVouch.bodies[i].upsotype == "rd")
                {
                    string cRdsId = pu_BillVouch.bodies[i].rdsid;
                    //string cInvCode = pu_BillVouch.bodies[i].cinvcode;
                    string sql = string.Format(@"SELECT a.cInvCode,c.cComUnitCode,b.cGroupCode,a.cassunit,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,
  po.ccode,po.cDepCode,po.cPersonCode,po.cVenCode,po.cPTCode,po.cexch_name,po.iTaxRate, po.cBusType, a.bTaxCost,  a.iTaxPrice,
b.bInvQuality,a.btaxcost,a.iposid
FROM dbo.rdrecords01 a
   INNER JOIN dbo.rdrecord01 po ON a.id=po.id
  INNER JOIN dbo.Inventory b  ON a.cInvCode=b.cInvCode
  INNER JOIN inventory_sub d ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c ON a.cassunit=c.cComunitCode
  WHERE a.autoid = '{0}' ", cRdsId);
                    DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                    if (dt.Rows.Count == 0)
                    {
                        return string.Format("第{0}行存货编码ID不正确", (i + 1).ToString());
                    }
                    else
                    {
                        pu_BillVouch.bodies[i].cgroupcode = DbHelper.GetDbString(dt.Rows[0]["cGroupCode"]);
                        pu_BillVouch.bodies[i].btaxcost = DbHelper.GetDbString(dt.Rows[0]["btaxcost"]);
                        pu_BillVouch.bodies[i].iposid = DbHelper.GetDbString(dt.Rows[0]["iposid"]);
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cassunit"])))
                        {
                            pu_BillVouch.bodies[i].cunitid = DbHelper.GetDbString(dt.Rows[0]["cassunit"]);
                            if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                            {
                                pu_BillVouch.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                                pu_BillVouch.bodies[i].inum = (DbHelper.GetDbdecimal(pu_BillVouch.bodies[i].ipbvquantity) / DbHelper.GetDbdecimal(dt.Rows[0]["iChangRate"])).ToString("0.000000");
                            }
                        }
                    }

                }
                else
                {

                    string cPosId = pu_BillVouch.bodies[i].iposid;
                    //string cInvCode = pu_BillVouch.bodies[i].cinvcode;
                    string sql = string.Format(@"SELECT a.cInvCode,b.cComUnitCode,b.cGroupCode,a.cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,
  po.cPOID,po.cDepCode,po.cPersonCode,po.cVenCode,po.cPTCode,po.cexch_name,po.iTaxRate,po.nflat,po.cBusType, a.bGsp,a.bTaxCost,a.iPerTaxRate, a.iTaxPrice,
b.bInvQuality,a.btaxcost
FROM dbo.PO_Podetails a with(nolock)
   INNER JOIN dbo.PO_Pomain po with(nolock) ON a.POID=po.POID
  INNER JOIN dbo.Inventory b  with(nolock) ON a.cInvCode=b.cInvCode
  INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON a.cUnitID=c.cComunitCode
  WHERE a.id = '{0}' ", cPosId);
                    DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                    if (dt.Rows.Count == 0)
                    {
                        return string.Format("第{0}行存货编码ID不正确", (i + 1).ToString());
                    }
                    else
                    {
                        pu_BillVouch.bodies[i].cgroupcode = DbHelper.GetDbString(dt.Rows[0]["cGroupCode"]);
                        pu_BillVouch.bodies[i].btaxcost = DbHelper.GetDbString(dt.Rows[0]["btaxcost"]);
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                        {
                            pu_BillVouch.bodies[i].cunitid = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);
                            if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                            {
                                pu_BillVouch.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                                pu_BillVouch.bodies[i].inum = (DbHelper.GetDbdecimal(pu_BillVouch.bodies[i].ipbvquantity) / DbHelper.GetDbdecimal(dt.Rows[0]["iChangRate"])).ToString("0.000000");
                            }
                        }
                    }
                }

                //处理项目
                string cItemCode = pu_BillVouch.bodies[i].citemcode;

                if (!string.IsNullOrEmpty(cItemCode))
                {
                    if (cConstr.Contains("606"))
                    {
                        string sql = string.Format(@"select a.citemname,b.cItemCcode,b.cItemCname from fitemss01 a with(nolock)
inner join fitemss01class b with(nolock) on a.citemccode = b.cItemCcode
where a.citemcode = '{0}'", cItemCode);
                        DataTable dtxm = DbHelper2.ExecuteTable(sql, cConstr);
                        if (dtxm.Rows.Count > 0)
                        {
                            pu_BillVouch.bodies[i].citemname = DbHelper.GetDbString(dtxm.Rows[0]["citemname"]);
                            pu_BillVouch.bodies[i].citem_class = "01";
                            pu_BillVouch.bodies[i].citem_name = "研发项目";
                        }
                        else
                        {
                            return string.Format("第{0}行项目编码录入不正确", (i + 1).ToString());
                        }

                    }
                    else
                    {
                        string sql = string.Format(@"select a.citemname,b.cItemCcode,b.cItemCname from fitemss97 a with(nolock)
inner join fitemss97class b with(nolock) on a.citemccode = b.cItemCcode
where a.citemcode = '{0}'", cItemCode);
                        DataTable dtxm = DbHelper2.ExecuteTable(sql, cConstr);
                        if (dtxm.Rows.Count > 0)
                        {
                            pu_BillVouch.bodies[i].citemname = DbHelper.GetDbString(dtxm.Rows[0]["citemname"]);
                            pu_BillVouch.bodies[i].citem_class = "97";
                            pu_BillVouch.bodies[i].citem_name = "项目管理";
                        }
                        else
                        {
                            return string.Format("第{0}行项目编码录入不正确", (i + 1).ToString());
                        }
                    }

                }

            }
            return "ok";
        }

        public static string GetPUArrivalInfo(PuArrivalVouch pu_ArrivalVouch, string cConstr)
        {
            if (pu_ArrivalVouch == null)
            {
                return "Error: 没有数据";
            }
            if (pu_ArrivalVouch.bodies == null)
            {
                return "Error: 没有表体数据";
            }
            //var listSummary = from p in pu_ArrivalVouch.bodies
            //                              group p by new { iposid = p.iposid } into g
            //                     select new
            //                     {
            //                         iposid = g.Key.iposid,
            //                         iquantity = g.Sum(a =>DbHelper.GetDbdecimal(a.iquantity))
            //                     } ;
            //超采购订单到货的校验
            //foreach(var lstgroup in listSummary)
            //{
            //    string cPosId = lstgroup.iposid;
            //    decimal dQty = lstgroup.iquantity;
            //    string sql= "SELECT COUNT(*)  FROM dbo.PO_Podetails WHERE id='{0}' AND iQuantity<ISNULL(iArrQTY,0)+{0} "

            //}
            for (int i = 0; i < pu_ArrivalVouch.bodies.Count; i++)
            {

                string cPosId = pu_ArrivalVouch.bodies[i].iposid;
                string cInvCode = pu_ArrivalVouch.bodies[i].cinvcode;
                string sql = string.Format(@"SELECT a.cInvCode,b.cComUnitCode,b.cGroupCode,a.cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,
  po.cPOID,po.cDepCode,po.cPersonCode,po.cVenCode,po.cPTCode,po.cexch_name,po.iTaxRate,po.nflat,po.cBusType, a.bGsp,a.bTaxCost,a.iPerTaxRate, a.iTaxPrice,
b.bInvQuality,b.cinvdefine2,b.bfree1,a.cfree1
FROM dbo.PO_Podetails a with(nolock)
   INNER JOIN dbo.PO_Pomain po with(nolock) ON a.POID=po.POID
  INNER JOIN dbo.Inventory b  with(nolock) ON a.cInvCode=b.cInvCode
  INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON a.cUnitID=c.cComunitCode
  WHERE a.id = '{0}' ", cPosId);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行订单ID不正确，查询不到订单", (i + 1).ToString());
                }
                else
                {
                    if (DbHelper.GetDbString(dt.Rows[0]["cInvCode"]) != pu_ArrivalVouch.bodies[i].cinvcode)
                    {
                        return string.Format("第{0}行订单物料和{1}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]));
                    }
                    //写表头信息
                    if (i == 0)
                    {
                        pu_ArrivalVouch.head.cptcode = DbHelper.GetDbString(dt.Rows[0]["cPTCode"]);
                        pu_ArrivalVouch.head.cvencode = DbHelper.GetDbString(dt.Rows[0]["cVenCode"]);
                        //if (string.IsNullOrEmpty(pu_ArrivalVouch.head.cdepcode)) {

                        string cDepcode = DbHelper.GetDbString(dt.Rows[0]["cDepCode"]);
                        pu_ArrivalVouch.head.cdepcode = DataChuli.getNewDepCode(cDepcode, cConstr);
                        pu_ArrivalVouch.head.cpersoncode = DbHelper.GetDbString(dt.Rows[0]["cPersonCode"]);
                        //}


                        pu_ArrivalVouch.head.cpocode = DbHelper.GetDbString(dt.Rows[0]["cPOID"]);
                        pu_ArrivalVouch.head.cexch_name = DbHelper.GetDbString(dt.Rows[0]["cexch_name"]);
                        pu_ArrivalVouch.head.itaxrate = DbHelper.GetDbString(dt.Rows[0]["iTaxRate"]);
                        pu_ArrivalVouch.head.iexchrate = DbHelper.GetDbString(dt.Rows[0]["nflat"]);
                        pu_ArrivalVouch.head.cbustype = DbHelper.GetDbString(dt.Rows[0]["cBusType"]);

                    }
                    pu_ArrivalVouch.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]);
                    pu_ArrivalVouch.bodies[i].bgsp = DbHelper.GetDbString(dt.Rows[0]["bGsp"]);
                    pu_ArrivalVouch.bodies[i].btaxcost = DbHelper.GetDbString(dt.Rows[0]["bTaxCost"]);
                    pu_ArrivalVouch.bodies[i].itaxrate = DbHelper.GetDbString(dt.Rows[0]["iPerTaxRate"]);
                    pu_ArrivalVouch.bodies[i].cgroupcode = DbHelper.GetDbString(dt.Rows[0]["cGroupCode"]);
                    pu_ArrivalVouch.bodies[i].ioritaxcost = DbHelper.GetDbString(dt.Rows[0]["iTaxPrice"]);

                    decimal dSum = Math.Round(DbHelper.GetDbdecimal(dt.Rows[0]["iTaxPrice"]) * DbHelper.GetDbdecimal(pu_ArrivalVouch.bodies[i].iquantity), 2);
                    decimal dMoney = Math.Round(dSum / (1 + DbHelper.GetDbdecimal(dt.Rows[0]["iPerTaxRate"]) / 100), 2);
                    decimal dTax = dSum - dMoney;
                    decimal ioricost = dMoney / DbHelper.GetDbdecimal(pu_ArrivalVouch.bodies[i].iquantity);
                    decimal dExch = DbHelper.GetDbdecimal(dt.Rows[0]["nflat"]);
                    pu_ArrivalVouch.bodies[i].ioricost = ioricost.ToString("0.000.000000");
                    pu_ArrivalVouch.bodies[i].iorisum = dSum.ToString("0.00");
                    pu_ArrivalVouch.bodies[i].iorimoney = dMoney.ToString("0.00");
                    pu_ArrivalVouch.bodies[i].ioritaxprice = (dSum - dMoney).ToString("0.00");
                    pu_ArrivalVouch.bodies[i].imoney = (dMoney * dExch).ToString("0.00");
                    pu_ArrivalVouch.bodies[i].icost = (ioricost * dExch).ToString("0.000000");

                    pu_ArrivalVouch.bodies[i].isum = (dSum * dExch).ToString("0.00");
                    //rdrecord.bodies[i].imoney = (dMoney * dExch).ToString("0.00");  //累计结算金额，不能写
                    pu_ArrivalVouch.bodies[i].itaxprice = ((dSum - dMoney) * dExch).ToString("0.00");


                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                    {
                        pu_ArrivalVouch.bodies[i].cunitid = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);
                        pu_ArrivalVouch.bodies[i].igrouptype = "1";
                        pu_ArrivalVouch.bodies[i].inum = DbHelper.GetDbString(DbHelper.GetDbdecimal(pu_ArrivalVouch.bodies[i].iquantity) / DbHelper.GetDbdecimal(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])));
                    }
                    else
                    {
                        pu_ArrivalVouch.bodies[i].igrouptype = "0";
                    }

                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                    {
                        pu_ArrivalVouch.bodies[i].cunitid = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);

                    }

                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    if (CanShu.bfree1check == "1")
                    {
                        if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            pu_ArrivalVouch.bodies[i].cfree1 = DataChuli.getBanben(pu_ArrivalVouch.bodies[i].cfree1);
                            //}
                            if (DbHelper.GetDbString(dt.Rows[0]["cfree1"]) != pu_ArrivalVouch.bodies[i].cfree1)
                            {
                                return string.Format("第{0}行{1}到货单版本{2}和采购订单版本{3}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]),
                                  DbHelper.GetDbString(dt.Rows[0]["cfree1"]), pu_ArrivalVouch.bodies[i].cfree1);
                            }
                        }
                        else
                        {
                            pu_ArrivalVouch.bodies[i].cfree1 = null;
                        }
                    }
                    else
                    {
                        //半成品的重新取，材料的不重新取
                        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //{
                        pu_ArrivalVouch.bodies[i].cfree1 = DataChuli.getBanben(pu_ArrivalVouch.bodies[i].cfree1);
                        //}
                    }


                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                    {
                        pu_ArrivalVouch.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                    }
                    if (!string.IsNullOrEmpty(pu_ArrivalVouch.bodies[i].cbatch))
                    {
                        //if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                        //{
                        //    pu_ArrivalVouch.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                        //    pu_ArrivalVouch.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                        //    if (string.IsNullOrEmpty(pu_ArrivalVouch.bodies[i].dpdate))
                        //    {
                        //        return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                        //    }
                        //    DateTime dMadedate = DbHelper.GetDbDate(pu_ArrivalVouch.bodies[i].dpdate);
                        //    //1 年 2 月 日
                        //    if (pu_ArrivalVouch.bodies[i].cmassunit == "1")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dvdate = dMadedate.AddYears(1).ToString("yyyy-MM-dd");
                        //    }
                        //    else if (pu_ArrivalVouch.bodies[i].cmassunit == "2")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dvdate = dMadedate.AddMonths(1).ToString("yyyy-MM-dd");
                        //    }
                        //    else if (pu_ArrivalVouch.bodies[i].cmassunit == "3")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dvdate = dMadedate.AddDays(1).ToString("yyyy-MM-dd");
                        //    }


                        //}
                        //if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                        //{
                        //    pu_ArrivalVouch.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                        //    if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(pu_ArrivalVouch.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                        //    }
                        //    else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dexpirationdate = DbHelper.GetDbDate(pu_ArrivalVouch.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                        //    }
                        //}

                    }

                }
            }
            return "ok";
        }

        public static string GetOMArrivalInfo(PuArrivalVouch pu_ArrivalVouch, string cConstr)
        {
            if (pu_ArrivalVouch == null)
            {
                return "Error: 没有数据";
            }
            if (pu_ArrivalVouch.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < pu_ArrivalVouch.bodies.Count; i++)
            {
                //通过imainmodetailsid 过度
                string cPosId = pu_ArrivalVouch.bodies[i].imainmodetailsid;
                string cInvCode = pu_ArrivalVouch.bodies[i].cinvcode;
                string sql = string.Format(@"SELECT a.cInvCode,b.cComUnitCode,b.cGroupCode,a.cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,
  po.cCode,po.cDepCode,po.cPersonCode,po.cVenCode,po.cPTCode,po.cexch_name,po.iTaxRate,po.nflat,po.cBusType, a.bGsp,a.bTaxCost,a.iPerTaxRate, a.iTaxPrice,
b.bInvQuality,a.iQuantity -isnull(a.iArrQTY,0) as wrksl,b.cinvdefine2,b.bfree1,a.cfree1
FROM dbo.OM_MODETAILS a with(nolock)
   INNER JOIN dbo.OM_MOMAIN po with(nolock) ON a.MOID=po.MOID
  INNER JOIN dbo.Inventory b  with(nolock) ON a.cInvCode=b.cInvCode
  INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON a.cUnitID=c.cComunitCode
  WHERE a.modetailsid = '{0}' ", cPosId);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行订单ID不正确，查询不到订单", (i + 1).ToString());
                }
                else
                {
                    if (DbHelper.GetDbString(dt.Rows[0]["cInvCode"]) != pu_ArrivalVouch.bodies[i].cinvcode)
                    {
                        return string.Format("第{0}行订单物料和{1}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]));
                    }
                    decimal dwrksl = DbHelper.GetDbdecimal(dt.Rows[0]["wrksl"]);
                    if (DbHelper.GetDbdecimal(pu_ArrivalVouch.bodies[i].iquantity) > dwrksl)
                    {
                        return string.Format("第{0}行订单数量超出未入库数量", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]));
                    }
                    //写表头信息
                    if (i == 0)
                    {
                        pu_ArrivalVouch.head.cptcode = DbHelper.GetDbString(dt.Rows[0]["cPTCode"]);
                        pu_ArrivalVouch.head.cvencode = DbHelper.GetDbString(dt.Rows[0]["cVenCode"]);
                        //if (string.IsNullOrEmpty(pu_ArrivalVouch.head.cdepcode))
                        //{
                        string cDepcode = DbHelper.GetDbString(dt.Rows[0]["cDepCode"]);
                        pu_ArrivalVouch.head.cdepcode = DataChuli.getNewDepCode(cDepcode, cConstr);
                        pu_ArrivalVouch.head.cpersoncode = DbHelper.GetDbString(dt.Rows[0]["cPersonCode"]);
                        //}

                        //pu_ArrivalVouch.head.cpersoncode = DbHelper.GetDbString(dt.Rows[0]["cPersonCode"]);
                        pu_ArrivalVouch.head.cpocode = DbHelper.GetDbString(dt.Rows[0]["cCode"]);
                        pu_ArrivalVouch.head.cexch_name = DbHelper.GetDbString(dt.Rows[0]["cexch_name"]);
                        pu_ArrivalVouch.head.itaxrate = DbHelper.GetDbString(dt.Rows[0]["iTaxRate"]);
                        pu_ArrivalVouch.head.iexchrate = DbHelper.GetDbString(dt.Rows[0]["nflat"]);
                        pu_ArrivalVouch.head.cbustype = DbHelper.GetDbString(dt.Rows[0]["cBusType"]);

                    }
                    pu_ArrivalVouch.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]);
                    pu_ArrivalVouch.bodies[i].bgsp = DbHelper.GetDbString(dt.Rows[0]["bGsp"]);
                    pu_ArrivalVouch.bodies[i].btaxcost = DbHelper.GetDbString(dt.Rows[0]["bTaxCost"]);
                    pu_ArrivalVouch.bodies[i].itaxrate = DbHelper.GetDbString(dt.Rows[0]["iPerTaxRate"]);
                    pu_ArrivalVouch.bodies[i].cgroupcode = DbHelper.GetDbString(dt.Rows[0]["cGroupCode"]);
                    pu_ArrivalVouch.bodies[i].ioritaxcost = DbHelper.GetDbString(dt.Rows[0]["iTaxPrice"]);
                    decimal dSum = Math.Round(DbHelper.GetDbdecimal(dt.Rows[0]["iTaxPrice"]) * DbHelper.GetDbdecimal(pu_ArrivalVouch.bodies[i].iquantity), 2);
                    decimal dMoney = Math.Round(dSum / (1 + DbHelper.GetDbdecimal(dt.Rows[0]["iPerTaxRate"]) / 100), 2);
                    decimal dTax = dSum - dMoney;
                    decimal ioricost = dMoney / DbHelper.GetDbdecimal(pu_ArrivalVouch.bodies[i].iquantity);
                    decimal dExch = DbHelper.GetDbdecimal(dt.Rows[0]["nflat"]);
                    pu_ArrivalVouch.bodies[i].ioricost = ioricost.ToString("0.000.000000");
                    pu_ArrivalVouch.bodies[i].iorisum = dSum.ToString("0.00");
                    pu_ArrivalVouch.bodies[i].iorimoney = dMoney.ToString("0.00");
                    pu_ArrivalVouch.bodies[i].ioritaxprice = (dSum - dMoney).ToString("0.00");
                    pu_ArrivalVouch.bodies[i].imoney = (dMoney * dExch).ToString("0.00");
                    pu_ArrivalVouch.bodies[i].icost = (ioricost * dExch).ToString("0.000000");

                    pu_ArrivalVouch.bodies[i].isum = (dSum * dExch).ToString("0.00");
                    //rdrecord.bodies[i].imoney = (dMoney * dExch).ToString("0.00");  //累计结算金额，不能写
                    pu_ArrivalVouch.bodies[i].itaxprice = ((dSum - dMoney) * dExch).ToString("0.00");


                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                    {
                        pu_ArrivalVouch.bodies[i].cunitid = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);
                        pu_ArrivalVouch.bodies[i].igrouptype = "1";
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                        {
                            pu_ArrivalVouch.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                            pu_ArrivalVouch.bodies[i].inum = DbHelper.GetDbString(DbHelper.GetDbdecimal(pu_ArrivalVouch.bodies[i].iquantity) / DbHelper.GetDbdecimal(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])));
                        }
                    }
                    else
                    {
                        pu_ArrivalVouch.bodies[i].igrouptype = "0";
                    }

                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    if (CanShu.bfree1check == "1")
                    {
                        if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            pu_ArrivalVouch.bodies[i].cfree1 = DataChuli.getBanben(pu_ArrivalVouch.bodies[i].cfree1);
                            //}
                            if (DbHelper.GetDbString(dt.Rows[0]["cfree1"]) != pu_ArrivalVouch.bodies[i].cfree1)
                            {
                                return string.Format("第{0}行{1}到货单版本{2}和委外订单版本{3}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]),
                                  DbHelper.GetDbString(dt.Rows[0]["cfree1"]), pu_ArrivalVouch.bodies[i].cfree1);
                            }
                        }
                        else
                        {
                            pu_ArrivalVouch.bodies[i].cfree1 = null;
                        }
                    }
                    else
                    {
                        //半成品的重新取，材料的不重新取
                        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //{
                        pu_ArrivalVouch.bodies[i].cfree1 = DataChuli.getBanben(pu_ArrivalVouch.bodies[i].cfree1);
                        //}
                    }




                    if (!string.IsNullOrEmpty(pu_ArrivalVouch.bodies[i].cbatch))
                    {
                        //if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                        //{
                        //    pu_ArrivalVouch.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                        //    pu_ArrivalVouch.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                        //    if (string.IsNullOrEmpty(pu_ArrivalVouch.bodies[i].dpdate))
                        //    {
                        //        return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                        //    }
                        //    DateTime dMadedate = DbHelper.GetDbDate(pu_ArrivalVouch.bodies[i].dpdate);
                        //    //1 年 2 月 日
                        //    if (pu_ArrivalVouch.bodies[i].cmassunit == "1")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dvdate = dMadedate.AddYears(1).ToString("yyyy-MM-dd");
                        //    }
                        //    else if (pu_ArrivalVouch.bodies[i].cmassunit == "2")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dvdate = dMadedate.AddMonths(1).ToString("yyyy-MM-dd");
                        //    }
                        //    else if (pu_ArrivalVouch.bodies[i].cmassunit == "3")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dvdate = dMadedate.AddDays(1).ToString("yyyy-MM-dd");
                        //    }


                        //}
                        //if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                        //{
                        //    pu_ArrivalVouch.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                        //    if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(pu_ArrivalVouch.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                        //    }
                        //    else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                        //    {
                        //        pu_ArrivalVouch.bodies[i].dexpirationdate = DbHelper.GetDbDate(pu_ArrivalVouch.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                        //    }
                        //}

                    }

                }
            }
            return "ok";
        }

        public static string GetST01ByCheckInfo(ST_Rdrecord01 rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {

                string cCheckId = rdrecord.bodies[i].icheckidbaks;
                string cInvCode = rdrecord.bodies[i].cinvcode;
                string sql = string.Format(@"SELECT a.cInvCode,b.cComUnitCode,b.cGroupCode,a.cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,
  po.cCode,qm.CPOCODE,po.cDepCode,po.cPersonCode,po.cVenCode,po.cPTCode,po.cexch_name, po.iExchRate,po.cBusType, a.bGsp,a.bTaxCost,a.iTaxRate, a.ioritaxcost
,po.dDate,qm.CCHECKCODE,a.iposid,a.autoid,qm.CCHECKPERSONCODE
FROM dbo.QMCHECKVOUCHER qm with(nolock)
INNER JOIN dbo.PU_ArrivalVouchs a with(nolock) ON qm.SOURCEAUTOID = a.Autoid 
   INNER JOIN dbo.PU_ArrivalVouch po with(nolock) ON a.id=po.id
  INNER JOIN dbo.Inventory b with(nolock) ON a.cInvCode=b.cInvCode
  INNER JOIN inventory_sub d  with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON a.cUnitID=c.cComunitCode
  WHERE qm.CVOUCHTYPE='QM03' AND  qm.id = '{0}' ", cCheckId);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行检验单ID不正确，查询不到检验单", (i + 1).ToString());
                }
                else
                {
                    if (DbHelper.GetDbString(dt.Rows[0]["cInvCode"]) != rdrecord.bodies[i].cinvcode)
                    {
                        return string.Format("第{0}行订单物料和{1}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]));
                    }
                    //写表头信息
                    if (i == 0)
                    {
                        rdrecord.head.cptcode = DbHelper.GetDbString(dt.Rows[0]["cPTCode"]);
                        rdrecord.head.cvencode = DbHelper.GetDbString(dt.Rows[0]["cVenCode"]);
                        rdrecord.head.cdepcode = DbHelper.GetDbString(dt.Rows[0]["cDepCode"]);
                        rdrecord.head.cpersoncode = DbHelper.GetDbString(dt.Rows[0]["cPersonCode"]);
                        rdrecord.head.cordercode = DbHelper.GetDbString(dt.Rows[0]["CPOCODE"]);
                        rdrecord.head.carvcode = DbHelper.GetDbString(dt.Rows[0]["cCode"]);
                        rdrecord.head.cexch_name = DbHelper.GetDbString(dt.Rows[0]["cexch_name"]);
                        rdrecord.head.itaxrate = DbHelper.GetDbString(dt.Rows[0]["iTaxRate"]);
                        rdrecord.head.iexchrate = DbHelper.GetDbString(dt.Rows[0]["iExchRate"]);
                        rdrecord.head.cbustype = DbHelper.GetDbString(dt.Rows[0]["cBusType"]);
                        rdrecord.head.darvdate = DbHelper.GetDbString(dt.Rows[0]["dDate"]);
                        rdrecord.head.cchkcode = DbHelper.GetDbString(dt.Rows[0]["CCHECKCODE"]);

                    }
                    rdrecord.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]);
                    rdrecord.bodies[i].btaxcost = DbHelper.GetDbString(dt.Rows[0]["bTaxCost"]);
                    rdrecord.bodies[i].itaxrate = DbHelper.GetDbString(dt.Rows[0]["iTaxRate"]);
                    //rdrecord.bodies[i]. = DbHelper.GetDbString(dt.Rows[0]["cGroupCode"]);
                    rdrecord.bodies[i].ioritaxcost = DbHelper.GetDbString(dt.Rows[0]["ioritaxcost"]);
                    rdrecord.bodies[i].iposid = DbHelper.GetDbString(dt.Rows[0]["iposid"]);
                    rdrecord.bodies[i].iarrsid = DbHelper.GetDbString(dt.Rows[0]["autoid"]);
                    rdrecord.bodies[i].ccheckcode = DbHelper.GetDbString(dt.Rows[0]["CCHECKCODE"]);
                    rdrecord.bodies[i].ccheckpersoncode = DbHelper.GetDbString(dt.Rows[0]["CCHECKPERSONCODE"]);
                    rdrecord.bodies[i].dcheckdate = DbHelper.GetDbString(dt.Rows[0]["autoid"]);
                    rdrecord.bodies[i].cpoid = DbHelper.GetDbString(dt.Rows[0]["CPOCODE"]);
                    rdrecord.bodies[i].cbarvcode = DbHelper.GetDbString(dt.Rows[0]["cCode"]);
                    rdrecord.bodies[i].dbarvdate = DbHelper.GetDbString(dt.Rows[0]["dDate"]);

                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                    {
                        rdrecord.bodies[i].cassunit = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);
                    }

                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                    {
                        rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);

                    }
                    if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                    {
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                        {
                            rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                            rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                            if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                            {
                                return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                            }
                            DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                            //1 年 2 月 日
                            if (rdrecord.bodies[i].cmassunit == "1")
                            {
                                rdrecord.bodies[i].dvdate = dMadedate.AddYears(1).ToString("yyyy-MM-dd");
                            }
                            else if (rdrecord.bodies[i].cmassunit == "2")
                            {
                                rdrecord.bodies[i].dvdate = dMadedate.AddMonths(1).ToString("yyyy-MM-dd");
                            }
                            else if (rdrecord.bodies[i].cmassunit == "3")
                            {
                                rdrecord.bodies[i].dvdate = dMadedate.AddDays(1).ToString("yyyy-MM-dd");
                            }


                        }
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                        {
                            rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                            if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                            {
                                rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                            }
                            else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                            {
                                rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                            }
                        }

                    }

                }
            }
            return "ok";
        }

        

        public static string GetST10ByMOInfo(ref ST_Rdrecord10 rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {
                string cModid = rdrecord.bodies[i].impoids;
                string cInvCode = rdrecord.bodies[i].cinvcode;

                if (!string.IsNullOrWhiteSpace(cModid))
                {
                    string sql = string.Format(@"SELECT a.InvCode,b.cComUnitCode,b.cGroupCode,a.AuxUnitCode,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,
 mo.MoCode,a.MDeptCode,a.SoCode,a.SoType,a.MoLotCode  ,a.SortSeq,a.moid,b.binvbatch,b.cinvdefine2,b.bfree1,e.cDepCode
FROM dbo.mom_orderdetail a  with(nolock)
INNER JOIN mom_order mo with(nolock) ON a.MoId=mo.MoId
  INNER JOIN dbo.Inventory b with(nolock)  ON a.InvCode=b.cInvCode
  INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON a.AuxUnitCode=c.cComunitCode
 LEFT JOIN dbo.[Cust_OpDep] e ON a.Free1 = e.cOpCode
  WHERE a.modid = '{0}' ", cModid);
                    DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                    if (dt.Rows.Count == 0)
                    {
                        return string.Format("第{0}行生产订单ID不正确，查询不到生产订单", (i + 1).ToString());
                    }
                    else
                    {
                        if (DbHelper.GetDbString(dt.Rows[0]["InvCode"]) != rdrecord.bodies[i].cinvcode)
                        {
                            return string.Format("第{0}行订单物料和{1}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]));
                        }
                        //写表头信息
                        if (i == 0)
                        {
                            rdrecord.head.cdepcode = DbHelper.GetDbString(dt.Rows[0]["cDepCode"]);
                            if (string.IsNullOrEmpty(rdrecord.head.cdepcode))
                            {
                                ExLog.WriteTxt(sql);
                                return string.Format("{0}工序无对应部门", rdrecord.bodies[i].cdefine22);
                            }
                            rdrecord.head.cmpocode = DbHelper.GetDbString(dt.Rows[0]["MoCode"]);
                            rdrecord.head.iproorderid = DbHelper.GetDbString(dt.Rows[0]["moid"]);
                            //if (string.IsNullOrEmpty(rdrecord.head.crdcode))
                            //{
                            //    rdrecord.head.crdcode = CanShu.Rd10;
                            //}
                        }
                        //rdrecord10.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]); 
                        rdrecord.bodies[i].cmocode = DbHelper.GetDbString(dt.Rows[0]["MoCode"]);
                        rdrecord.bodies[i].imoseq = DbHelper.GetDbString(dt.Rows[0]["SortSeq"]);
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["AuxUnitCode"])))
                        {
                            rdrecord.bodies[i].cassunit = DbHelper.GetDbString(dt.Rows[0]["AuxUnitCode"]);
                            if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                            {
                                rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);

                            }
                            rdrecord.bodies[i].inum = DbHelper.GetDbString(DbHelper.GetDbdecimal(rdrecord.bodies[i].iquantity) / DbHelper.GetDbdecimal(dt.Rows[0]["iChangRate"]));
                        }

                        if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                        {
                            rdrecord.bodies[i].cbatch = CanShu.cbatch;
                        }
                        //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                        if (CanShu.bfree1check == "1")
                        {
                            if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                            {
                                //半成品的重新取，材料的不重新取
                                //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                                //{
                                rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                                //}
                                //不检查版本是否一样
                            }
                            else
                            {
                                rdrecord.bodies[i].cfree1 = null;
                            }
                        }
                        else
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                            //}
                        }

                        //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                        //{
                        //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                        //    {
                        //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                        //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                        //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                        //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                        //        {
                        //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                        //        }
                        //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                        //        //1 年 2 月 日
                        //        if (rdrecord.bodies[i].cmassunit == "1")
                        //        {
                        //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                        //        }
                        //        else if (rdrecord.bodies[i].cmassunit == "2")
                        //        {
                        //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                        //        }
                        //        else if (rdrecord.bodies[i].cmassunit == "3")
                        //        {
                        //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                        //        }


                        //    }
                        //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                        //    {
                        //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                        //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                        //        {
                        //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                        //        }
                        //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                        //        {
                        //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                        //        }
                        //    }

                        //}
                    }


                }
                else
                {
                    string sql = string.Format(@"
SELECT b.cInvCode,b.cComUnitCode,b.cGroupCode, 
b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,b.binvbatch,b.cinvdefine2,b.bfree1
FROM  dbo.Inventory b  with(nolock)
  INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode 
  WHERE b.cInvCode = '{0}' ", cInvCode);
                    DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                    if (dt.Rows.Count == 0)
                    {
                        return string.Format("第{0}行存货编码不正确", (i + 1).ToString());
                    }
                    else
                    {
                        if (i == 0)
                        {
                            if (string.IsNullOrEmpty(rdrecord.head.cdepcode))
                            {
                                string sqlDept = string.Format(@"select [cDepCode] from [Cust_OpDep] where [cOpCode] = '{0}'", ComFunc.GetAZ(rdrecord.bodies[i].cdefine22));
                                //ExLog.WriteTxt(sqlDept);
                                string cDepCode = DbHelper.GetDbString(DbHelper2.ExecuteScalar(sqlDept, CanShu.conStr));
                                if (string.IsNullOrEmpty(cDepCode))
                                {
                                    return string.Format("{0}工序无对应部门", rdrecord.bodies[i].cdefine22);
                                }
                                rdrecord.head.cdepcode = cDepCode;
                            }
                            if (string.IsNullOrEmpty(rdrecord.head.crdcode))
                            {
                                rdrecord.head.crdcode = CanShu.scRd10;
                            }
                        }


                        if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                        {
                            rdrecord.bodies[i].cbatch = CanShu.cbatch;
                        }
                        //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                        //if (CanShu.bfree1check == "1")
                        //{
                        //    if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        //    {
                        //        //半成品的重新取，材料的不重新取
                        //        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //        //{
                        //        rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                        //        //}
                        //    }
                        //    else
                        //    {
                        //        rdrecord.bodies[i].cfree1 = null;
                        //    }
                        //}
                        //else
                        //{
                        //    //半成品的重新取，材料的不重新取
                        //    //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //    //{
                        //    rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                        //    //}
                        //}
                    }
                }
            }
            return "ok";
        }

        /// <summary>
        /// 根据生产订单取材料出库信息
        /// </summary>
        /// <param name="rdrecord"></param>
        /// <param name="cConstr"></param>
        /// <returns></returns>
        public static string GetST11ByMOInfo(ST_Rdrecord11 rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            string citemname = null;
            string citem_class = null;
            string citem_name = null;
            if (!string.IsNullOrWhiteSpace(rdrecord.bodies[0].citemcode))
            {
                //取第一行读取项目信息
                string sql1 = string.Format(@"select a.citemname,b.cItemCcode,b.cItemCname from fitemss97 a with(nolock)
inner join fitemss97class b with(nolock) on a.citemccode = b.cItemCcode
where a.citemcode = '{0}'", rdrecord.bodies[0].citemcode);
                DataTable dtxm = DbHelper2.ExecuteTable(sql1, cConstr);
                if (dtxm.Rows.Count > 0)
                {
                    citemname = DbHelper.GetDbString(dtxm.Rows[0]["citemname"]);
                    citem_class = "97";
                    citem_name = "项目管理";
                }
                else
                {
                    return string.Format("第1行项目编码录入不正确");
                }
            }




            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {

                string Allocateid = rdrecord.bodies[i].impoids;
                string cInvCode = rdrecord.bodies[i].cinvcode;
                //区分工单领料和试产领料，试产领料是无关联材料出库单
                if (!string.IsNullOrWhiteSpace(Allocateid))
                {
                    string sql = string.Format(@"SELECT a.InvCode,b.cComUnitCode,b.cGroupCode,a.AuxUnitCode,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,
 a1.MDeptCode,a.SoCode,a.SoType,a1.MoLotCode,mo.MoCode  ,a1.SortSeq,b.binvbatch,b.cinvdefine2,b.bfree1 
FROM dbo.mom_moallocate a with(nolock) 
inner join mom_orderdetail a1 with(nolock) on a.modid = a1.ModId
inner join mom_order mo with(nolock) on a1.MoId = mo.MoId
  INNER JOIN dbo.Inventory b with(nolock)  ON a.invcode=b.cInvCode
  INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON a.AuxUnitCode=c.cComunitCode
  WHERE a.AllocateId = '{0}' ", Allocateid);
                    DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                    if (dt.Rows.Count == 0)
                    {
                        return string.Format("第{0}行生产订单ID不正确，查询不到生产订单", (i + 1).ToString());
                    }
                    else
                    {

                        //写表头信息
                        if (i == 0)
                        {


                            rdrecord.head.cdepcode = DbHelper.GetDbString(dt.Rows[0]["MDeptCode"]);

                            rdrecord.head.cmpocode = DbHelper.GetDbString(dt.Rows[0]["MoCode"]);
                            if (string.IsNullOrEmpty(rdrecord.head.crdcode))
                            {
                                rdrecord.head.crdcode = CanShu.Rd11MO;
                            }

                        }
                        //rdrecord10.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]); 
                        rdrecord.bodies[i].cmocode = DbHelper.GetDbString(dt.Rows[0]["MoCode"]);
                        rdrecord.bodies[i].imoseq = DbHelper.GetDbString(dt.Rows[0]["SortSeq"]);
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cComUnitCode"])))
                        {
                            rdrecord.bodies[i].cassunit = DbHelper.GetDbString(dt.Rows[0]["cComUnitCode"]);
                        }

                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                        {
                            rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                        }



                        int iFree1 = DbHelper.GetDbInt(dt.Rows[0]["bfree1"]);

                        if (cInvCode != DbHelper.GetDbString(dt.Rows[0]["InvCode"]))
                        {
                            sql = string.Format(@"SELECT  bfree1 ,binvbatch
FROM  dbo.Inventory  
  WHERE cinvcode = '{0}' ", cInvCode);
                            DataTable dt2 = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                            if (dt2.Rows.Count > 0)
                            {
                                iFree1 = DbHelper.GetDbInt(dt2.Rows[0]["bfree1"]);
                                if (DbHelper.GetDbInt(dt2.Rows[0]["binvbatch"]) == 1)
                                {
                                    rdrecord.bodies[i].cbatch = CanShu.cbatch;
                                }
                            }
                        }
                        else
                        {
                            if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                            {
                                rdrecord.bodies[i].cbatch = CanShu.cbatch;
                            }
                        }
                        //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                        if (CanShu.bfree1check == "1")
                        {
                            if (iFree1 == 1)
                            {
                                //半成品的重新取，材料的不重新取
                                //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品")
                                //{
                                rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                                //}
                            }
                            else
                            {
                                rdrecord.bodies[i].cfree1 = null;
                            }
                        }
                        else
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品")
                            //{
                            rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                            //}
                        }

                        //                        if (DbHelper.GetDbString(dt.Rows[0]["InvCode"]) != rdrecord.bodies[i].cinvcode)
                        //                        {
                        //                            //return string.Format("第{0}行订单物料和{1}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["InvCode"]));
                        //                            //判断是否替代料

                        //                            //没有使用
                        //                            sql = string.Format(@"select moallocatesubid from mom_moallocatesub  a,bas_part b   
                        //where allocateid='{0}' and a.partid=b.partid and b.invcode='{1}'  ", rdrecord.bodies[i].impoids,
                        //rdrecord.bodies[i].cinvcode);
                        //                            var subid = SqlsugarHelper.Instance.Ado.GetScalar(sql);
                        //                            if (subid != null)
                        //                            {
                        //                                rdrecord.bodies[i].bsupersede = "1";
                        //                                rdrecord.bodies[i].isupersedeqty = rdrecord.bodies[i].iquantity;
                        //                                rdrecord.bodies[i].isupersedempoids = rdrecord.bodies[i].impoids;
                        //                                rdrecord.bodies[i].imoallocatesubid = DbHelper.GetDbString(subid);
                        //                                //rdrecord.bodies[i].impoids = null;  
                        //                            }
                        //                            else
                        //                            {
                        //                                 return string.Format("第{0}行订单物料和{1}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["InvCode"]));
                        //                            }

                        //                        }


                        //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                        //{
                        //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                        //    {
                        //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                        //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                        //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                        //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                        //        {
                        //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                        //        }
                        //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                        //        //1 年 2 月 日
                        //        if (rdrecord.bodies[i].cmassunit == "1")
                        //        {
                        //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                        //        }
                        //        else if (rdrecord.bodies[i].cmassunit == "2")
                        //        {
                        //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                        //        }
                        //        else if (rdrecord.bodies[i].cmassunit == "3")
                        //        {
                        //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                        //        }


                        //    }
                        //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                        //    {
                        //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                        //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                        //        {
                        //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                        //        }
                        //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                        //        {
                        //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                        //        }
                        //    }

                        //}
                        //项目信息
                        if (!string.IsNullOrWhiteSpace(citem_class))
                        {
                            rdrecord.bodies[i].citem_class = citem_class;
                            rdrecord.bodies[i].citemcname = citem_name;
                            rdrecord.bodies[i].cname = citemname;

                        }
                    }
                }
                else
                {
                    string sql = string.Format(@"
SELECT b.cInvCode,b.cComUnitCode,b.cGroupCode, 
b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,b.binvbatch,b.cinvdefine2,b.bfree1
FROM  dbo.Inventory b with(nolock) 
  INNER JOIN inventory_sub d  with(nolock) ON b.cInvCode=d.cInvSubCode 
  WHERE b.cInvCode = '{0}' ", cInvCode);
                    DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                    if (dt.Rows.Count == 0)
                    {
                        return string.Format("第{0}行存货编码不正确", (i + 1).ToString());
                    }
                    else
                    {
                        if (i == 0)
                        {
                            if (string.IsNullOrEmpty(rdrecord.head.cdepcode))
                            {
                                rdrecord.head.cdepcode = CanShu.scdep;
                            }
                            if (string.IsNullOrEmpty(rdrecord.head.crdcode))
                            {
                                rdrecord.head.crdcode = CanShu.scRd11;
                            }
                        }


                        //辅助计量单位不考虑
                        //if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                        //{
                        //    rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);

                        //}
                        if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                        {
                            rdrecord.bodies[i].cbatch = CanShu.cbatch;
                        }
                        //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                        if (CanShu.bfree1check == "1")
                        {
                            if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                            {
                                //半成品的重新取，材料的不重新取
                                //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                                //{
                                rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                                //}
                            }
                            else
                            {
                                rdrecord.bodies[i].cfree1 = null;
                            }
                        }
                        else
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                            //}
                        }
                        //注释掉，一径不用
                        //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                        //{
                        //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                        //    {
                        //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                        //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                        //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                        //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                        //        {
                        //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                        //        }
                        //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                        //        //1 年 2 月 日
                        //        if (rdrecord.bodies[i].cmassunit == "1")
                        //        {
                        //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                        //        }
                        //        else if (rdrecord.bodies[i].cmassunit == "2")
                        //        {
                        //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                        //        }
                        //        else if (rdrecord.bodies[i].cmassunit == "3")
                        //        {
                        //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                        //        }


                        //    }
                        //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                        //    {
                        //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                        //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                        //        {
                        //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                        //        }
                        //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                        //        {
                        //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                        //        }
                        //    }

                        //}
                        //项目信息
                        if (!string.IsNullOrWhiteSpace(citem_class))
                        {
                            rdrecord.bodies[i].citem_class = citem_class;
                            rdrecord.bodies[i].citemcname = citem_name;
                            rdrecord.bodies[i].cname = citemname;

                        }
                    }
                }
            }
            return "ok";
        }


        public static string GetST32ByDispInfo(ST_Rdrecord32 rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {

                string cdlsId = rdrecord.bodies[i].idlsid;
                string cInvCode = rdrecord.bodies[i].cinvcode;
                string sql = string.Format(@"SELECT a.cInvCode,b.cComUnitCode,b.cGroupCode,a.cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,
  po.cDLCode ,po.cDepCode,po.cPersonCode,po.cCusCode,po.csTCode,po.cexch_name, po.iExchRate,po.cBusType, a.bGsp,a.iTaxRate, a.iUnitPrice
,po.dDate, a.isosid,a.idlsid ,a.cordercode,a.iorderrowno ,po.csocode,po.dlid,a.citemcode,a.citemname,a.cItem_class,cItem_CName
,b.binvbatch,b.cinvdefine2,b.bfree1,a.cfree1
FROM   dbo.DispatchLists a  with(nolock) 
   INNER JOIN dbo.DispatchList po with(nolock) ON a.dlid=po.dlid 
  INNER JOIN dbo.Inventory b with(nolock)  ON a.cInvCode=b.cInvCode
  INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON a.cUnitID=c.cComunitCode
  WHERE a.idlsid  = '{0}' ", cdlsId);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行发货单ID不正确，查询不到发货单", (i + 1).ToString());
                }
                else
                {
                    if (DbHelper.GetDbString(dt.Rows[0]["cInvCode"]) != rdrecord.bodies[i].cinvcode)
                    {
                        return string.Format("第{0}行订单物料和{1}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]));
                    }
                    //写表头信息
                    if (i == 0)
                    {
                        rdrecord.head.cstcode = DbHelper.GetDbString(dt.Rows[0]["cSTCode"]);
                        rdrecord.head.ccuscode = DbHelper.GetDbString(dt.Rows[0]["cCusCode"]);
                        rdrecord.head.cdepcode = DbHelper.GetDbString(dt.Rows[0]["cDepCode"]);
                        rdrecord.head.cpersoncode = DbHelper.GetDbString(dt.Rows[0]["cPersonCode"]);
                        rdrecord.head.cordercode = DbHelper.GetDbString(dt.Rows[0]["csocode"]);
                        rdrecord.head.cdlcode = DbHelper.GetDbString(dt.Rows[0]["dlid"]);
                        rdrecord.head.cbuscode = DbHelper.GetDbString(dt.Rows[0]["cDLCode"]);
                        rdrecord.head.cbustype = DbHelper.GetDbString(dt.Rows[0]["cBusType"]);
                        rdrecord.head.cinvoicecompany = DbHelper.GetDbString(dt.Rows[0]["cCusCode"]);
                        //rdrecord01.head.cchkcode = DbHelper.GetDbString(dt.Rows[0]["CCHECKCODE"]);

                    }
                    rdrecord.bodies[i].cbdlcode = DbHelper.GetDbString(dt.Rows[0]["cDLCode"]);
                    rdrecord.bodies[i].cpesocode = DbHelper.GetDbString(dt.Rows[0]["cordercode"]);
                    rdrecord.bodies[i].ipesoseq = DbHelper.GetDbString(dt.Rows[0]["iorderrowno"]);
                    rdrecord.bodies[i].ipesodid = DbHelper.GetDbString(dt.Rows[0]["isosid"]);
                    rdrecord.bodies[i].isotype = "0";


                    rdrecord.bodies[i].citemcode = DbHelper.GetDbString(dt.Rows[0]["citemcode"]);


                    rdrecord.bodies[i].cname = DbHelper.GetDbString(dt.Rows[0]["citemname"]);
                    rdrecord.bodies[i].citem_class = DbHelper.GetDbString(dt.Rows[0]["cItem_class"]);
                    rdrecord.bodies[i].citemcname = DbHelper.GetDbString(dt.Rows[0]["cItem_CName"]);


                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cComUnitCode"])))
                    {
                        rdrecord.bodies[i].cassunit = DbHelper.GetDbString(dt.Rows[0]["cComUnitCode"]);

                    }

                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                    {
                        rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);

                    }
                    if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                    {
                        rdrecord.bodies[i].cbatch = CanShu.cbatch;
                    }
                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    if (CanShu.bfree1check == "1")
                    {
                        if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                            if (DbHelper.GetDbString(dt.Rows[0]["cfree1"]) != rdrecord.bodies[i].cfree1)
                            {
                                return string.Format("第{0}行{1}发货单版本{2}和出库单版本{3}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]),
                                DbHelper.GetDbString(dt.Rows[0]["cfree1"]), rdrecord.bodies[i].cfree1);
                            }
                            //}
                        }
                        else
                        {
                            rdrecord.bodies[i].cfree1 = null;
                        }
                    }
                    else
                    {
                        //半成品的重新取，材料的不重新取
                        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //{
                        rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                        //}
                    }
                    //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                    //{
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                    //    {
                    //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                    //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                    //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                    //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                    //        {
                    //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                    //        }
                    //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                    //        //1 年 2 月 日
                    //        if (rdrecord.bodies[i].cmassunit == "1")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "2")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "3")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                    //        }


                    //    }
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                    //    {
                    //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                    //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //    }

                    //}

                }
            }
            return "ok";
        }


        public static string GetST11Info(ST_Rdrecord11 rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {


                string cInvCode = rdrecord.bodies[i].cinvcode;
                string sql = string.Format(@"SELECT b.cInvCode,b.cComUnitCode,b.cGroupCode,
b.cSTComUnitCode AS cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu ,b.binvbatch,b.cinvdefine2,b.bfree1
FROM   dbo.Inventory b  
  INNER JOIN inventory_sub d ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c ON b.cSTComUnitCode=c.cComunitCode
  WHERE b.cinvcode  = '{0}' ", cInvCode);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行存货编码ID不正确", (i + 1).ToString());
                }
                else
                {

                    //rdrecord.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]);
                    if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                    {
                        rdrecord.bodies[i].cbatch = CanShu.cbatch;
                    }
                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    //if (CanShu.bfree1check == "1")
                    //{
                    //    if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                    //    {
                    //        //半成品的重新取，材料的不重新取
                    //        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                    //        //{
                    //        rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                    //        //}
                    //    }
                    //    else
                    //    {
                    //        rdrecord.bodies[i].cfree1 = null;
                    //    }
                    //}
                    //else
                    //{
                    //    //半成品的重新取，材料的不重新取
                    //    //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                    //    //{
                    //    rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                    //    //}
                    //}

                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cComUnitCode"])))
                    {
                        rdrecord.bodies[i].cassunit = DbHelper.GetDbString(dt.Rows[0]["cComUnitCode"]);

                    }

                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                    {
                        rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);

                    }

                    //处理项目
//                    string cItemCode = rdrecord.bodies[i].citemcode;

//                    if (!string.IsNullOrEmpty(cItemCode))
//                    {
//                        if (cConstr.Contains("606"))
//                        {
//                            sql = string.Format(@"select a.citemname,b.cItemCcode,b.cItemCname from fitemss01 a with(nolock)
//inner join fitemss01class b with(nolock) on a.citemccode = b.cItemCcode
//where a.citemcode = '{0}'", cItemCode);
//                            DataTable dtxm = DbHelper2.ExecuteTable(sql, cConstr);
//                            if (dtxm.Rows.Count > 0)
//                            {
//                                rdrecord.bodies[i].cname = DbHelper.GetDbString(dtxm.Rows[0]["citemname"]);
//                                rdrecord.bodies[i].citem_class = "01";
//                                rdrecord.bodies[i].citemcname = "研发项目";
//                            }
//                            else
//                            {
//                                return string.Format("第{0}行项目编码录入不正确", (i + 1).ToString());
//                            }

//                        }
//                        else
//                        {
//                            sql = string.Format(@"select a.citemname,b.cItemCcode,b.cItemCname from fitemss97 a
//inner join fitemss97class b on a.citemccode = b.cItemCcode
//where a.citemcode = '{0}'", cItemCode);
//                            DataTable dtxm = DbHelper2.ExecuteTable(sql, cConstr);
//                            if (dtxm.Rows.Count > 0)
//                            {
//                                rdrecord.bodies[i].cname = DbHelper.GetDbString(dtxm.Rows[0]["citemname"]);
//                                rdrecord.bodies[i].citem_class = "97";
//                                rdrecord.bodies[i].citemcname = "项目管理";
//                            }
//                            else
//                            {
//                                return string.Format("第{0}行项目编码录入不正确", (i + 1).ToString());
//                            }
//                        }

//                    }


                    //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                    //{
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                    //    {
                    //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                    //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                    //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                    //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                    //        {
                    //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                    //        }
                    //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                    //        //1 年 2 月 日
                    //        if (rdrecord.bodies[i].cmassunit == "1")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "2")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "3")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                    //        }


                    //    }
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                    //    {
                    //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                    //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //    }

                    //}

                }
            }
            return "ok";
        }

        public static string GetST08Info(ST_Rdrecord08 rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {


                string cInvCode = rdrecord.bodies[i].cinvcode;
                string sql = string.Format(@"SELECT b.cInvCode,b.cComUnitCode,b.cGroupCode,
b.cSTComUnitCode AS cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu ,b.binvbatch,b.cinvdefine2,b.bfree1
FROM   dbo.Inventory b  with(nolock) 
  INNER JOIN inventory_sub d with(nolock)  ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON b.cSTComUnitCode=c.cComunitCode
  WHERE b.cinvcode  = '{0}' ", cInvCode);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行存货编码ID不正确", (i + 1).ToString());
                }
                else
                {

                    //rdrecord.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]);

                    if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                    {
                        rdrecord.bodies[i].cbatch = CanShu.cbatch;
                    }
                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    if (CanShu.bfree1check == "1")
                    {
                        if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                            //}
                        }
                        else
                        {
                            rdrecord.bodies[i].cfree1 = null;
                        }
                    }
                    else
                    {
                        //半成品的重新取，材料的不重新取
                        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //{
                        rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                        //}
                    }
                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                    {
                        rdrecord.bodies[i].cassunit = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                        {
                            rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                            rdrecord.bodies[i].inum = DbHelper.GetDbString(DbHelper.GetDbdecimal(rdrecord.bodies[i].iquantity) / DbHelper.GetDbdecimal(rdrecord.bodies[i].iinvexchrate));
                        }
                    }
                    //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                    //{
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                    //    {
                    //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                    //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                    //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                    //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                    //        {
                    //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                    //        }
                    //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                    //        //1 年 2 月 日
                    //        if (rdrecord.bodies[i].cmassunit == "1")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "2")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "3")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                    //        }


                    //    }
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                    //    {
                    //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                    //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //    }

                    //}

                }
            }
            return "ok";
        }

        public static string GetST09Info(ST_Rdrecord09 rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }
            string citemname = null;
            string citem_class = null;
            string citem_name = null;
            if (!string.IsNullOrWhiteSpace(rdrecord.bodies[0].citemcode))
            {
                //取第一行读取项目信息
                string sql1 = string.Format(@"select a.citemname,b.cItemCcode,b.cItemCname from fitemss97 a with(nolock)
inner join fitemss97class b with(nolock) on a.citemccode = b.cItemCcode
where a.citemcode = '{0}'", rdrecord.bodies[0].citemcode);
                DataTable dtxm = DbHelper2.ExecuteTable(sql1, cConstr);
                if (dtxm.Rows.Count > 0)
                {
                    citemname = DbHelper.GetDbString(dtxm.Rows[0]["citemname"]);
                    citem_class = "97";
                    citem_name = "项目管理";
                }
                else
                {
                    return string.Format("第1行项目编码录入不正确");
                }
            }
            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {


                string cInvCode = rdrecord.bodies[i].cinvcode;
                string sql = string.Format(@"SELECT b.cInvCode,b.cComUnitCode,b.cGroupCode,
b.cSTComUnitCode AS cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu ,b.binvbatch,b.cinvdefine2,b.bfree1
FROM   dbo.Inventory b with(nolock)  
  INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON b.cSTComUnitCode=c.cComunitCode
  WHERE b.cinvcode  = '{0}' ", cInvCode);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行存货编码ID不正确", (i + 1).ToString());
                }
                else
                {

                    rdrecord.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]);

                    if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                    {
                        rdrecord.bodies[i].cbatch = CanShu.cbatch;
                    }
                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    if (CanShu.bfree1check == "1")
                    {
                        if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        {
                            ////半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                            //}
                        }
                        else
                        {
                            rdrecord.bodies[i].cfree1 = null;
                        }
                    }
                    else
                    {
                        //半成品的重新取，材料的不重新取
                        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //{
                        rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                        //}
                    }
                    //项目信息
                    if (!string.IsNullOrWhiteSpace(citem_class))
                    {
                        rdrecord.bodies[i].citem_class = citem_class;
                        rdrecord.bodies[i].citemcname = citem_name;
                        rdrecord.bodies[i].cname = citemname;

                    }
                    //if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                    //{
                    //    rdrecord.bodies[i].cassunit = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                    //    {
                    //        rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                    //        rdrecord.bodies[i].inum = DbHelper.GetDbString(DbHelper.GetDbdecimal(rdrecord.bodies[i].iquantity) /DbHelper.GetDbdecimal(rdrecord.bodies[i].iinvexchrate));
                    //    }
                    //}


                    //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                    //{
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                    //    {
                    //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                    //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                    //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                    //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                    //        {
                    //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                    //        }
                    //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                    //        //1 年 2 月 日
                    //        if (rdrecord.bodies[i].cmassunit == "1")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "2")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "3")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                    //        }


                    //    }
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                    //    {
                    //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                    //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //    }

                    //}

                }
            }
            return "ok";
        }

        public static string GetST09ByBorrow(ST_Rdrecord09 rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {

                string cdlsId = rdrecord.bodies[i].idebitids;
                string sql = string.Format(@"select a.cCODE, a.ctype,a.bobjectcode,a.cdepcode,  b.cInvCode,
a1.cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu ,b.binvbatch,b.cinvdefine2,b.bfree1,a1.cfree1
from HY_DZ_BorrowOut   a with(nolock)
	inner join HY_DZ_BorrowOuts a1 with(nolock) on a.id = a1.id
	inner  join Inventory b with(nolock)  ON a1.cInvCode=b.cInvCode
	 INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON b.cSTComUnitCode=c.cComunitCode 
where  
  a1.AutoID='{0}' ", cdlsId);
                DataTable dt = DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行借出单ID不正确，查询不到借出单", (i + 1).ToString());
                }
                else
                {
                    if (DbHelper.GetDbString(dt.Rows[0]["cInvCode"]) != rdrecord.bodies[i].cinvcode)
                    {
                        return string.Format("第{0}行借出物料和{1}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]));
                    }
                    //写表头信息
                    if (i == 0)
                    {
                        rdrecord.head.cbuscode = DbHelper.GetDbString(dt.Rows[0]["cCODE"]);

                        if (DbHelper.GetDbString(dt.Rows[0]["ctype"]) == "客户")
                        {
                            rdrecord.head.ccuscode = DbHelper.GetDbString(dt.Rows[0]["bobjectcode"]);

                        }
                        else if (DbHelper.GetDbString(dt.Rows[0]["ctype"]) == "部门")
                        {
                            rdrecord.head.cdepcode = DbHelper.GetDbString(dt.Rows[0]["bobjectcode"]);

                        }

                        if (string.IsNullOrEmpty(rdrecord.head.cdepcode))
                        {
                            rdrecord.head.cdepcode = DbHelper.GetDbString(dt.Rows[0]["cDepCode"]);
                        }



                    }
                    //rdrecord.bodies[i].citemcode = DbHelper.GetDbString(dt.Rows[0]["citemcode"]);
                    //rdrecord.bodies[i].cname = DbHelper.GetDbString(dt.Rows[0]["citemname"]);
                    //rdrecord.bodies[i].citem_class = DbHelper.GetDbString(dt.Rows[0]["cItem_class"]);
                    //rdrecord.bodies[i].citemcname = DbHelper.GetDbString(dt.Rows[0]["cItem_CName"]);
                    int cinvbatch = DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]);
                    if (cinvbatch == 1)
                    {
                        rdrecord.bodies[i].cbatch = CanShu.cbatch;
                    }
                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    if (CanShu.bfree1check == "1")
                    {
                        if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        {
                            ////半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                            //}
                            if (DbHelper.GetDbString(dt.Rows[0]["cfree1"]) != rdrecord.bodies[i].cfree1)
                            {
                                return string.Format("第{0}行{1}出库单版本{2}和借出单版本{3}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]),
                                  DbHelper.GetDbString(dt.Rows[0]["cfree1"]), rdrecord.bodies[i].cfree1);
                            }
                        }
                        else
                        {
                            rdrecord.bodies[i].cfree1 = null;
                        }
                    }
                    else
                    {
                        //半成品的重新取，材料的不重新取
                        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //{
                        rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                        //}
                    }
                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                    {
                        rdrecord.bodies[i].cassunit = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                        {
                            rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                            rdrecord.bodies[i].inum = DbHelper.GetDbString(DbHelper.GetDbdecimal(rdrecord.bodies[i].iquantity) / DbHelper.GetDbdecimal(rdrecord.bodies[i].iinvexchrate));
                        }
                    }


                    //    if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                    //    {
                    //        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                    //        {
                    //            rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                    //            rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                    //            int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                    //            if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                    //            {
                    //                return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                    //            }
                    //            DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                    //            //1 年 2 月 日
                    //            if (rdrecord.bodies[i].cmassunit == "1")
                    //            {
                    //                rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                    //            }
                    //            else if (rdrecord.bodies[i].cmassunit == "2")
                    //            {
                    //                rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                    //            }
                    //            else if (rdrecord.bodies[i].cmassunit == "3")
                    //            {
                    //                rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                    //            }


                    //        }
                    //        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                    //        {
                    //            rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                    //            if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                    //            {
                    //                rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                    //            }
                    //            else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                    //            {
                    //                rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                    //            }
                    //        }

                    //}

                }
            }
            return "ok";
        }

        public static string GetST08ByReturn(ST_Rdrecord08 rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {

                string cdlsId = rdrecord.bodies[i].idebitids;
                string sql = string.Format(@"	select a.cCODE,a1.AutoID,a2.AutoID as AutoID2,a1.diffBack ,a1.cInvCode ,a1.cUnitID,c.iChangRate,
b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu,b.binvbatch ,b.cinvdefine2,b.bfree1,a1.cfree1
from HY_DZ_BorrowOutBack  a with(nolock)
	inner join HY_DZ_BorrowOutBacks a1 with(nolock) on a.id = a1.id
	inner join HY_DZ_BorrowOutBacks2 a2 with(nolock) on a2.UpAutoID = a1.AutoID
	inner  join Inventory b with(nolock)  ON a1.cInvCode=b.cInvCode
	 INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON b.cSTComUnitCode=c.cComunitCode
	 where   a1.AutoID={0}
  ", cdlsId);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行归还单ID不正确，查询不到归还单", (i + 1).ToString());
                }
                else
                {

                    if (DbHelper.GetDbString(dt.Rows[0]["diffBack"]) == "否" && DbHelper.GetDbString(dt.Rows[0]["cInvCode"]) != rdrecord.bodies[i].cinvcode)
                    {
                        return string.Format("第{0}行归还物料和{1}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]));
                    }
                    //写表头信息
                    if (i == 0)
                    {
                        rdrecord.head.cbuscode = DbHelper.GetDbString(dt.Rows[0]["cCODE"]);

                        if (string.IsNullOrEmpty(rdrecord.head.cdepcode))
                        {
                            rdrecord.head.cdepcode = DbHelper.GetDbString(dt.Rows[0]["cDepCode"]);
                        }



                    }
                    //rdrecord.bodies[i].citemcode = DbHelper.GetDbString(dt.Rows[0]["citemcode"]);
                    //rdrecord.bodies[i].cname = DbHelper.GetDbString(dt.Rows[0]["citemname"]);
                    //rdrecord.bodies[i].citem_class = DbHelper.GetDbString(dt.Rows[0]["cItem_class"]);
                    //rdrecord.bodies[i].citemcname = DbHelper.GetDbString(dt.Rows[0]["cItem_CName"]);

                    rdrecord.bodies[i].idebitchildids = DbHelper.GetDbString(dt.Rows[0]["AutoID2"]);
                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                    {
                        rdrecord.bodies[i].cassunit = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                        {
                            rdrecord.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                            rdrecord.bodies[i].inum = DbHelper.GetDbString(DbHelper.GetDbdecimal(rdrecord.bodies[i].iquantity) / DbHelper.GetDbdecimal(rdrecord.bodies[i].iinvexchrate));
                        }
                    }
                    if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                    {
                        rdrecord.bodies[i].cbatch = CanShu.cbatch;
                    }
                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    if (CanShu.bfree1check == "1")
                    {
                        if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                            //}
                            if (DbHelper.GetDbString(dt.Rows[0]["cfree1"]) != rdrecord.bodies[i].cfree1)
                            {
                                return string.Format("第{0}行{1}入库单版本{2}和归还单版本{3}不一致", (i + 1).ToString(), DbHelper.GetDbString(dt.Rows[0]["cInvCode"]),
                                  DbHelper.GetDbString(dt.Rows[0]["cfree1"]), rdrecord.bodies[i].cfree1);
                            }
                        }
                        else
                        {
                            rdrecord.bodies[i].cfree1 = null;
                        }
                    }
                    else
                    {
                        //半成品的重新取，材料的不重新取
                        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //{
                        rdrecord.bodies[i].cfree1 = DataChuli.getBanben(rdrecord.bodies[i].cfree1);
                        //}
                    }
                    //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                    //{
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                    //    {
                    //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                    //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                    //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                    //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                    //        {
                    //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                    //        }
                    //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                    //        //1 年 2 月 日
                    //        if (rdrecord.bodies[i].cmassunit == "1")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "2")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "3")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                    //        }


                    //    }
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                    //    {
                    //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                    //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //    }

                    //}

                }
            }
            return "ok";
        }

        public static string GetShapeChangeInfo(AssemVouch rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {


                string cInvCode = rdrecord.bodies[i].cInvCode;
                string sql = string.Format(@"SELECT b.cInvCode,b.cComUnitCode,b.cGroupCode, b.binvbatch,b.cinvdefine2,b.bfree1
FROM   dbo.Inventory b with(nolock)   
  WHERE b.cinvcode  = '{0}' ", cInvCode);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行存货编码ID不正确", (i + 1).ToString());
                }
                else
                {

                    //rdrecord.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]);

                    if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                    {
                        rdrecord.bodies[i].cAVBatch = CanShu.cbatch;
                    }
                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    if (CanShu.bfree1check == "1")
                    {
                        if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            rdrecord.bodies[i].cFree1 = DataChuli.getBanben(rdrecord.bodies[i].cFree1);
                            //}
                        }
                        else
                        {
                            rdrecord.bodies[i].cFree1 = null;
                        }
                    }
                    else
                    {
                        //半成品的重新取，材料的不重新取
                        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //{
                        rdrecord.bodies[i].cFree1 = DataChuli.getBanben(rdrecord.bodies[i].cFree1);
                        //}
                    }


                    //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                    //{
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                    //    {
                    //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                    //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                    //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                    //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                    //        {
                    //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                    //        }
                    //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                    //        //1 年 2 月 日
                    //        if (rdrecord.bodies[i].cmassunit == "1")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "2")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "3")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                    //        }


                    //    }
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                    //    {
                    //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                    //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //    }

                    //}

                }
            }
            return "ok";
        }

        public static string GetTransVouchInfo(ST_TransVouch rdrecord, string cConstr)
        {
            if (rdrecord == null)
            {
                return "Error: 没有数据";
            }
            if (rdrecord.bodies == null)
            {
                return "Error: 没有表体数据";
            }

            for (int i = 0; i < rdrecord.bodies.Count; i++)
            {


                string cInvCode = rdrecord.bodies[i].cInvCode;
                string sql = string.Format(@"SELECT b.cInvCode,b.cComUnitCode,b.cGroupCode, b.binvbatch,b.cinvdefine2,b.bfree1
FROM   dbo.Inventory b   with(nolock) 
  WHERE b.cinvcode  = '{0}' ", cInvCode);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行存货编码ID不正确", (i + 1).ToString());
                }
                else
                {

                    //rdrecord.bodies[i].cinvcode = DbHelper.GetDbString(dt.Rows[0]["cInvCode"]);

                    if (DbHelper.GetDbInt(dt.Rows[0]["binvbatch"]) == 1)
                    {
                        rdrecord.bodies[i].cTVBatch = CanShu.cbatch;
                    }

                    //写自由项,如果检查自由项1，则没有自由项的直接赋空值
                    if (CanShu.bfree1check == "1")
                    {
                        if (DbHelper.GetDbInt(dt.Rows[0]["bfree1"]) == 1)
                        {
                            //半成品的重新取，材料的不重新取
                            //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                            //{
                            rdrecord.bodies[i].cFree1 = DataChuli.getBanben(rdrecord.bodies[i].cFree1);
                            //}
                        }
                        else
                        {
                            rdrecord.bodies[i].cFree1 = null;
                        }
                    }
                    else
                    {
                        //半成品的重新取，材料的不重新取
                        //if (DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "半成品" || DbHelper.GetDbString(dt.Rows[0]["cinvdefine2"]) == "成品" )
                        //{
                        rdrecord.bodies[i].cFree1 = DataChuli.getBanben(rdrecord.bodies[i].cFree1);
                        //}
                    }
                    //if (!string.IsNullOrEmpty(rdrecord.bodies[i].cbatch))
                    //{
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                    //    {
                    //        rdrecord.bodies[i].cmassunit = DbHelper.GetDbString(dt.Rows[0]["cMassUnit"]);
                    //        rdrecord.bodies[i].imassdate = DbHelper.GetDbString(dt.Rows[0]["iMassDate"]);
                    //        int iMassdate = DbHelper.GetDbInt(dt.Rows[0]["iMassDate"]);
                    //        if (string.IsNullOrEmpty(rdrecord.bodies[i].dmadedate))
                    //        {
                    //            return string.Format("第{0}行订单物料生产日期未录入", (i + 1).ToString());
                    //        }
                    //        DateTime dMadedate = DbHelper.GetDbDate(rdrecord.bodies[i].dmadedate);
                    //        //1 年 2 月 日
                    //        if (rdrecord.bodies[i].cmassunit == "1")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddYears(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "2")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddMonths(iMassdate).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (rdrecord.bodies[i].cmassunit == "3")
                    //        {
                    //            rdrecord.bodies[i].dvdate = dMadedate.AddDays(iMassdate).ToString("yyyy-MM-dd");
                    //        }


                    //    }
                    //    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"])))
                    //    {
                    //        rdrecord.bodies[i].iexpiratdatecalcu = DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]);
                    //        if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "1")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).ToString("yyyy-MM-01")).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //        else if (DbHelper.GetDbString(dt.Rows[0]["iExpiratDateCalcu"]) == "2")
                    //        {
                    //            rdrecord.bodies[i].dexpirationdate = DbHelper.GetDbDate(rdrecord.bodies[i].dvdate).AddDays(-1).ToString("yyyy-MM-dd");
                    //        }
                    //    }

                    //}

                }
            }
            return "ok";
        }

        /// <summary>
        /// 货位调整 填写其他信息
        /// </summary>
        /// <param name="rdrecord10"></param>
        /// <param name="cConstr"></param>
        /// <returns></returns>
        public static string GetHWTZInfo(ST_AdjustPVouch entity, string cConstr)
        {
            if (entity == null)
            {
                return "Error: 没有数据";
            }
            if (entity.bodies == null)
            {
                return "Error: 没有表体数据";
            }
            string cposcode = entity.bodies[0].cBPosCode;
            string sqlwh = string.Format(@"SELECT cWhCode,bposend FROM dbo.Position with(nolock) WHERE cPosCode='{0}'   ", cposcode);
            DataTable dtwh = DbHelper2.ExecuteTable(sqlwh, cConstr);
            if (dtwh.Rows.Count == 0)
            {
                return "Error: 移出货位编码不存在";
            }
            else
            {
                int iEnd = DbHelper.GetDbInt(dtwh.Rows[0]["bposend"]);
                if (iEnd == 0)
                {
                    return "Error: 移出货位编码不是末级";
                }
                else
                {
                    string cWhcode = DbHelper.GetDbString(dtwh.Rows[0]["cWhCode"]);
                    entity.head.cWhCode = cWhcode;
                }
            }

            //移入货位
            cposcode = entity.bodies[0].cAPosCode;
            sqlwh = string.Format(@"SELECT cWhCode,bposend FROM dbo.Position WHERE cPosCode='{0}'   ", cposcode);
            dtwh = DbHelper2.ExecuteTable(sqlwh, cConstr);
            if (dtwh.Rows.Count == 0)
            {
                return "Error: 移入货位编码不存在";
            }
            else
            {
                int iEnd = DbHelper.GetDbInt(dtwh.Rows[0]["bposend"]);
                if (iEnd == 0)
                {
                    return "Error: 移入货位编码不是末级";
                }
                else
                {
                    string cWhcode = DbHelper.GetDbString(dtwh.Rows[0]["cWhCode"]);
                    if (entity.head.cWhCode != cWhcode)
                    {
                        return "Error: 移入移出货位编码不属于同一个仓库";
                    }
                }
            }

            for (int i = 0; i < entity.bodies.Count; i++)
            {


                string cInvCode = entity.bodies[i].cInvCode;
                string sql = string.Format(@"SELECT b.cInvCode,b.cComUnitCode,b.cGroupCode,c.cComunitCode,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu
 
FROM dbo.Inventory b  with(nolock)
  INNER JOIN inventory_sub d with(nolock) ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c with(nolock) ON b.cSTComUnitCode=c.cComunitCode
  WHERE b.cInvCode = '{0}' ", cInvCode);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行物料编码不正确", (i + 1).ToString());
                }
                else
                {


                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[i]["cComUnitCode"])))
                    {
                        entity.bodies[i].cAssUnit = DbHelper.GetDbString(dt.Rows[i]["cComUnitCode"]);

                    }

                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[i]["iChangRate"])))
                    {
                        entity.bodies[i].iNum = DbHelper.GetDbString(DbHelper.GetDbdecimal(entity.bodies[i].iQuantity) / DbHelper.GetDbdecimal(dt.Rows[i]["iChangRate"]));
                    }

                    if (!string.IsNullOrEmpty(entity.bodies[i].cBatch))
                    {
                        if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cMassUnit"])))
                        {
                            //取批次信息的保质期信息
                            sql = string.Format(@"SELECT cMassUnit,iMassDate,dMadeDate,dVDate,iExpiratDateCalcu,cExpirationdate,dExpirationdate FROM dbo.InvPositionSum with(nolock)
WHERE cinvcode='{0}' AND cBatch='{1}' AND cPosCode='{2}'", cInvCode, entity.bodies[i].cBatch, entity.bodies[i].cBPosCode);
                            DataTable dtbzq = DbHelper2.ExecuteTable(sql, cConstr);
                            if (dtbzq.Rows.Count == 0)
                            {
                                return string.Format("第{0}行物料移出货位无库存", (i + 1).ToString());
                            }
                            else
                            {
                                entity.bodies[i].dMadeDate = DbHelper.GetDbDate(dtbzq.Rows[0]["dMadeDate"]).ToString("yyyy-MM-dd");
                                entity.bodies[i].cMassUnit = DbHelper.GetDbString(dtbzq.Rows[0]["cMassUnit"]);
                                entity.bodies[i].iMassDate = DbHelper.GetDbString(dtbzq.Rows[0]["iMassDate"]);
                                entity.bodies[i].dDisDate = DbHelper.GetDbDate(dtbzq.Rows[0]["dVDate"]).ToString("yyyy-MM-dd");
                                entity.bodies[i].iExpiratDateCalcu = DbHelper.GetDbString(dtbzq.Rows[0]["iExpiratDateCalcu"]);
                                entity.bodies[i].cExpirationdate = DbHelper.GetDbString(dtbzq.Rows[0]["cExpirationdate"]);
                                if (!string.IsNullOrEmpty(DbHelper.GetDbString(dtbzq.Rows[0]["dExpirationdate"])))
                                {
                                    entity.bodies[i].cExpirationdate = DbHelper.GetDbDate(dtbzq.Rows[0]["dExpirationdate"]).ToString("yyyy-MM-dd");
                                }

                            }

                        }
                    }
                }
            }
            return "ok";
        }

        public static string GetSaleOrderInfo(SaleOrder so,string cConstr)
        {
            if (so == null)
            {
                return "Error: 没有数据";
            }
            if (so.bodies == null)
            {
                return "Error: 没有表体数据";
            }
            string sqlFactory = "select top 1 cFactoryCode from Factory order by bDefaultFactory desc,cFactoryCode";
            string cFactoryCode = DbHelper.GetDbString(DbHelper2.ExecuteScalar(sqlFactory, CanShu.conStr));


            for (int i = 0; i < so.bodies.Count; i++)
            {
                string cInvCode = so.bodies[i].cinvcode;
                string sql = string.Format(@"SELECT b.cInvCode,b.cComUnitCode,b.cGroupCode,
b.cSTComUnitCode AS cUnitID,c.iChangRate,b.cMassUnit,b.iMassDate,d.iExpiratDateCalcu 
FROM   dbo.Inventory b  
  INNER JOIN inventory_sub d ON b.cInvCode=d.cInvSubCode
  LEFT JOIN dbo.ComputationUnit c ON b.cSTComUnitCode=c.cComunitCode
  WHERE b.cinvcode  = '{0}' ", cInvCode);
                DataTable dt = fuzhu.DbHelper2.ExecuteTable(sql, cConstr);
                if (dt.Rows.Count == 0)
                {
                    return string.Format("第{0}行存货编码ID不正确", (i + 1).ToString());
                }
                else
                {
                    so.bodies[i].cgroupcode = DbHelper.GetDbString(dt.Rows[0]["cGroupCode"]);
                    if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["cUnitID"])))
                    {
                        so.bodies[i].cunitid = DbHelper.GetDbString(dt.Rows[0]["cUnitID"]);
                        so.bodies[i].igrouptype = "1";
                        //if (!string.IsNullOrEmpty(DbHelper.GetDbString(dt.Rows[0]["iChangRate"])))
                        //{
                        //    so.bodies[i].iinvexchrate = DbHelper.GetDbString(dt.Rows[0]["iChangRate"]);
                        //    so.bodies[i].fnum = (DbHelper.GetDbdecimal(so.bodies[i].fquantity) / DbHelper.GetDbdecimal(dt.Rows[0]["iChangRate"])).ToString("0.000000");
                        //}
                    }
                    else
                    {
                        so.bodies[i].igrouptype = "0";
                    }

                    so.bodies[i].cfactorycode = cFactoryCode;


                }
            }
            return "ok";
        }

    }
}
